package com.ruoyi.app.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wuliu.domain.TLeaveMessage;
import com.ruoyi.web.wuliu.service.ITLeaveMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 留言Controller
 * 
 * @author ruoyi
 * @date 2023-12-05
 */
@RestController
@RequestMapping("/app/wuliu/lmessage")
public class AppTLeaveMessageController extends BaseController
{
    @Autowired
    private ITLeaveMessageService tLeaveMessageService;

    /**
     * 查询留言列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:lmessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TLeaveMessage tLeaveMessage)
    {
        startPage();
        List<TLeaveMessage> list = tLeaveMessageService.selectTLeaveMessageList(tLeaveMessage);
        return getDataTable(list);
    }

    /**
     * 获取留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:lmessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tLeaveMessageService.selectTLeaveMessageById(id));
    }

    /**
     * 新增留言
     */
    @PreAuthorize("@ss.hasPermi('wuliu:lmessage:add')")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLeaveMessage tLeaveMessage)
    {
        return toAjax(tLeaveMessageService.insertTLeaveMessage(tLeaveMessage));
    }

    /**
     * 修改留言
     */
    @PreAuthorize("@ss.hasPermi('wuliu:lmessage:edit')")
    @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLeaveMessage tLeaveMessage)
    {
        return toAjax(tLeaveMessageService.updateTLeaveMessage(tLeaveMessage));
    }

    /**
     * 删除留言
     */
    @PreAuthorize("@ss.hasPermi('wuliu:lmessage:remove')")
    @Log(title = "留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tLeaveMessageService.deleteTLeaveMessageByIds(ids));
    }
}
